<?php
namespace App\Libs\ZiNiao;

use App\Libs\ZiNiao\Request\AppTokenRequest;
use App\Libs\ZiNiao\Common\OpenClient;
use Exception;
class RequireAppToken
{
    public function getAppToken(OpenClient $openClient)
    {
        $request = new AppTokenRequest();
        $result = $openClient->execute($request);// 发送请求
        $result_decode = json_decode($result);
        if (($result_decode->code === 0 or $result_decode->code === '0') and !isset($result_decode->sub_code)) {
            return $result_decode->data->appAuthToken;
        }else {
            report(new Exception('AppToken失败:' . $result,214));
            die(0);
        }
    }

}
